package com.web.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by reeves on 2015/8/18.
 */
public class QuotationTransfer {

    public static String processQuotationMarks(String content) {

        // 将"**"转为“**”
        String regex = "\"([^\"]*)\"";
        //"([^"]*)"
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(content);

        String reCT = content;

        while (matcher.find()) {
            String itemMatch = "“" + matcher.group(1) + "”";
            reCT = reCT.replace("\"" + matcher.group(1) + "\"", itemMatch);
        }

        // 将"**”转为“**”
        regex = "\"([^\"”]*)”";
        pattern = Pattern.compile(regex);
        matcher = pattern.matcher(reCT);

        while (matcher.find()) {
            String itemMatch1 = "“" + matcher.group(1) + "”";
            reCT = reCT.replace("\"" + matcher.group(1) + "”", itemMatch1);
        }

        // 将“**"转为“**”
        regex = "“([^\"“]*)\"";
        pattern = Pattern.compile(regex);
        matcher = pattern.matcher(reCT);

        while (matcher.find()) {
            String itemMatch1 = "“" + matcher.group(1) + "”";
            reCT = reCT.replace("“" + matcher.group(1) + "\"", itemMatch1);
        }

        return reCT;
    }

    /*public static void main(String[] args) {
        String output = processQuotationMarks("《小王子》:永远不该迷失的\"小王子\"");
        System.out.println(output);
    }*/

}
